<template>
  <section class="icons">
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img :src="item.imgUrl" :alt="item.content">
            <p>{{item.content}}</p>
          </div>
        </div>
      </swiper-slide>

      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </section>
</template>

<script>
export default {
  name: 'Icons',
  props: {
    iconList: Array
  },
  data () {
    return {
      // iconList: [
      //   {id: '0001', content: '景点门票', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png'},
      //   {id: '0002', content: '水上乐园', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/3e/86314b2af03b7502.png'},
      //   {id: '0003', content: '必游榜单', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png'},
      //   {id: '0004', content: '成都定制游', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/95/8d02011d149bdb02.png'},
      //   {id: '0005', content: '亲子游', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/50/26ffa31b56646402.png'},
      //   {id: '0006', content: '蓉城七景', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/20/831d62d2e1c7be02.png'},
      //   {id: '0007', content: '成都周边', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/b6/37560ece9c62b502.png'},
      //   {id: '0008', content: 'Q+精选', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ed/cf572be30fc32f02.png'},
      //   {id: '0009', content: 'Q+精选', imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ed/cf572be30fc32f02.png'}
      // ],
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true,
        initialSlide: 0
      }
    }
  },
  computed: {
    pages () {
      let pages = []
      this.iconList.forEach((value, key) => {
        let page = Math.floor(key / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(value)
      })
      return pages
    }
  }
}
</script>

<style lang="less" scoped>
  @import '~styles/varibles.less';
  @import '~styles/mixins.less';
  .icons /deep/ .swiper-container {
    height: 0;
    padding-bottom: 50%;
    overflow: hidden;
  }
  .icons {
    margin-top: .1rem;
  }
  .icon {
    width: 25%;
    padding-bottom: 25%;
    float: left;
    position: relative;
    height: 0;
  }
  .icon-img {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: .44rem;
    box-sizing: border-box;
    padding: .1rem;
  }
  img {
    height: 62%;
    display: block;
    margin: 0 auto;
  }
  p {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: .44rem;
    line-height: .44rem;
    color: @darkTextColor;
    text-align: center;
    font-size: .3rem;
    .ellipsis();
  }
</style>
